package com.bw.user.mvvm.viewmodel;

import com.bw.greendao.dao.DaoSessionUtils;
import com.bw.greendao.entity.UserEntity;
import com.bw.mvvm_common.entity.BaseEntity;
import com.bw.mvvm_common.mvvm.viewmodel.BaseViewModel;
import com.bw.user.adapter.OrderListAdapter;
import com.bw.user.entity.OrderListEntity;
import com.bw.user.mvvm.model.OrderListModel;

import java.util.HashMap;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @author KK
 * @description:
 * @date :2021/11/2 15:17
 */
public class OffViewModel extends BaseViewModel<OrderListModel> {

    public OrderListAdapter adapter = new OrderListAdapter();
    @Override
    public void oncreate() {
        super.oncreate();
        List<UserEntity> list = DaoSessionUtils.getInstance().getSession().queryBuilder(UserEntity.class).list();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("orderStatus",3);
        hashMap.put("userId",list.get(0).getUser_id());
        m.requestObserList(hashMap)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(this);
    }

    @Override
    protected void result(BaseEntity baseEntity) {
        if(baseEntity instanceof OrderListEntity){
            OrderListEntity orderListEntity = (OrderListEntity) baseEntity;
            adapter.setNewInstance(orderListEntity.getData());
        }
    }
}
